<template>
	<view class="popup-login">

		<view style="padding: 40rpx;width:600rpx;">
			<view style="font-size: 36rpx;font-weight: bold;text-align: center;margin-bottom: 20rpx;">用户协议</view>
			<view class="f26"
				style="margin-bottom: 20rpx;line-height: 44rpx;display: flex;align-items: center;flex-wrap: wrap;">
				感谢您对Labulado的信任和支持！ 为更好地保护您的个人信息安全，请您仔细阅读并理解我们最新<span @click="goArticleInfo(4)"
					class="xieyi">《Labulado用户服务协议》</span>
				<span class="xieyi" @click="goArticleInfo(5)">《Labulado用户隐私协议》</span>
				我们将严格按照您同意的协议中的各项条款使用和保护您的个人信息。
			</view>
			<view class="u-flex" style="justify-content: center;margin-bottom:20rpx">
				<u-checkbox size="28" icon-size="20" label-size="0" v-model="aggree" shape="circle"
					active-color="red"></u-checkbox><text @click="aggree=!aggree">已阅读并同意以上协议</text>
			</view>
			<view class="u-flex">

				<view class="btn1 btn3 fz14 mr10" @click="toClose">取消</view>
				<view class="btn1 fz14 ml10" @click="toLogin">同意</view>

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "nothing",
		props: {
			text: {
				type: String,
				default: '暂无内容~'
			}
		},
		data() {
			return {
				aggree: false,
				wxCode:'',
				disabledLogin:false,
			};
		},
		created() {
			this.getCode()
		},
		methods: {
			getCode() {
				uni.login({
					success: res => {
						if (res.code) {
							this.wxCode = res.code
						} else {
							//login成功，但是没有取到code
							uni.showToast({
								title: '未取得code',
								icon: 'none'
							});
						}
					},
					fail: function(res) {
						uni.showToast({
							title: '用户授权失败wx.login',
							icon: 'none'
						});
					}
				});
			},
			wxLogin() {
			uni.showLoading({
				title: '授权登陆中！'
			});
				return new Promise((resolve, reject) => {
					this.$api.wxLogin({
						code: this.wxCode
					}, res => {
						uni.hideLoading()
						if (res.code == 200) {
							this.$db.set("userToken", res.data.token);
							this.$db.set("openid", res.data.openid);
							this.openid = res.data.openid
							uni.removeStorage({
								key: 'jump'
							})
							resolve(res.data.openid)
						} else {
							this.disabledLogin = false
							console.log(res.message, 11111)
							reject(res.message)
							this.getCode()
							uni.showToast({
								title: res.message,
								icon: 'none'
							});
						}
					})

				})
			},
			async toLogin() {
				if (!this.aggree) {
					uni.showToast({
						title: '请先阅读协议！',
						icon: 'none'
					});
					return
				}
				if (this.disabledLogin) {
					return
				}
				this.disabledLogin = true
				await this.wxLogin()

				this.$common.successToShow('登录成功', ress => {
					this.$emit('sureLogin')
				})
			},
			toClose() {
				this.$emit('close')
			},
		}
	}
</script>

<style lang="scss">
	.popup-login {
		.login-btn {

			position: fixed;
			bottom: 50px;
			left: 0;
			right: 0;
			padding: 30rpx;
		}

		.btn1 {

			width: 100%;
			height: 88rpx;
			text-align: center;
			color: #fff;
			line-height: 88rpx;
			background: #76BC21;
			border-radius: 40px;
		}

		.btn3 {
			background: none;
			border: 1px solid #76BC21;
			color: #76BC21;
		}

		.btn2 {

			width: 100%;
			height: 88rpx;
			text-align: center;
			color: #fff;
			margin-top: 20rpx;
			line-height: 88rpx;
		}
	}
</style>